import { BlockEnum } from '@/components/workflow/types'
import { generateUUID } from '@/utils'
import { ALL_COMPLETION_AVAILABLE_BLOCKS } from '../../constants'
import { LoopNodeType } from './types'
import { Variable } from 'lucide-react'

export const getLoopDefaultParams = () => {
  return {
    max_loop_times: 1,
    inputList: [
      {
        id: generateUUID(8),
        type: 'cite',
        label: '迭代数组',
        variable: '',
        required: true,
        value: '',
        variableType: '',
      }
    ],
    filter:{
      logic: 'and',
      rules: [
      ]
    },
    outputList: [
      {
      }
    ],
  }
}

export default {
  getAvailablePrevNodes() {
    // 迭代器节点只能连接非End节点
    const nodes = ALL_COMPLETION_AVAILABLE_BLOCKS.filter(type => type !== BlockEnum.End)
    return nodes
  },
  getAvailableNextNodes() {
    // 迭代器节点可以连接所有节点
    return ALL_COMPLETION_AVAILABLE_BLOCKS
  },

  // 检查节点是否有效
  checkValid: (payload: LoopNodeType) => {
    // 检查是否有输入数组
    if(!payload.inputList?.[0]?.value) {
      return false
    }
    return true
  },

  // 检查是否可以建立连接
  isValidConnection: (connection) => {
    const { source, target } = connection;
    // 检查是否为同一个迭代器内的节点
    if (source.parentId && target.parentId) {
      return source.parentId === target.parentId;
    }
    return true;
  }
}